package com.apkcore.bl;

public class _7整数反转 {
    public int reverse2(int x) {
        long res = 0;
        while (x != 0) {
            res = x % 10 + res * 10;
            if (res == Integer.MAX_VALUE || res == Integer.MIN_VALUE) {
                return 0;
            }
            x /= 10;
        }
        return (int) res;
    }

    public int reverse(int x) {
        int res = 0;
        while (x != 0) {
            int preRes = res;
            res = x % 10 + preRes * 10;
            if ((res - x % 10) / 10 != preRes) {
                return 0;
            }
            x /= 10;
        }
        return res;
    }

    public static void main(String[] args) {
        System.out.println(new _7整数反转().reverse(1235));
        System.out.println(new _7整数反转().reverse(Integer.MAX_VALUE));
    }
}
